package com.example.myapplication.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class dengLu extends AppCompatActivity {
    EditText edt1, edt2;
    ImageView img1;
    SharedPreferences sp;
    SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_deng_lu);
        sp = getSharedPreferences("zhanghaomima", MODE_PRIVATE);
        editor = sp.edit();
        initView();
    }

    private void initView() {
        edt1 = findViewById(R.id.zhanghao);
        edt2 = findViewById(R.id.mima);
        img1 = findViewById(R.id.img_denglu);
        String s = sp.getString("zhanghao", "");
        edt1.setText(s);
        img1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String zhanghao = edt1.getText().toString();
                String mima = edt2.getText().toString();
                if (zhanghao.equals("123") && mima.equals("123")) {
                    editor.putString("zhanghao", zhanghao);
                    editor.putString("mima", mima);
                    editor.putInt("flag", 1);
                    editor.commit();
                    // 登录成功后返回之前的Activity
                    Intent intent = new Intent();
                    intent.setClass(dengLu.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    Toast.makeText(dengLu.this, "登录失败", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}